# 做了三种水瓶的代码，但事例时只用了按比例分配的水平
import random

def bottle_rate(water, n, order, i, j):  # 按比例分配水量的瓶子,water:水量；n:其连接的下一行水瓶的数量
    rate = eval(input('请以元组的形式输入水量的分配比例（小数）：'))
    for x in range(n[j]):
        bottle[order - j + i + n[j - 1] + x] += bottle[order] * rate[x]


def bottle_abs(water, n, order, i, j):  # 按绝对值分配水量的瓶子
    water_allocation = eval(input('请以元组的形式输入具体水量的分配'))
    for x in range(n[j]):
        bottle[order - j + i + n[j - 1] + x] += water_allocation[x]


def bottle_random(water, n, order, i, j):  # 随机分配水量的瓶子
    ls=[]
    ls.append(random.randint(1,100))
    for i in range(n[j]-2): 
        ls.append(random.randint(1,100-ls[-1]))
    end = 100
    for i in ls:
        end -= i
    ls.append(end)
    for x in range(n[j]):
        bottle[order - j + i + n[j - 1] + x] += bottle[order] * ls[x]

def main(data, water):  # data包括每一行的瓶子数量
    order = 0
    for i in data:
        if i < data[-1]:  # 最后一行没有水瓶
            print('这是第{}行'.format(i))
            n = eval(input('请以元组的形式输入其连接的下一行水瓶的数量，请在结尾处添加一个‘0’:'))
            for j in range(i):
                order += 1
                bottle_rate(water, n, order, i, j)


data = eval(input('请以元组的方式输入每一行的水瓶数量，例如(k1,k2,k3)：'))
water = eval(input('请输入水量：'))

# 初始化所有水瓶,并给与第一批水瓶“注水”
bottle = {}
end_bottle = {}
way_0 = 0
for i in range(len(data)):
    for j in range(data[i]):
        way_0 += 1
        bottle[way_0] = 0
way_0 -= data[-1]
for i in range(data[0]):
    bottle[i + 1] = water

main(data, water)  # 启动“灌水瓶模型”

for i in range(data[-1]):
    way_0 += 1
    end_bottle[way_0] = bottle[way_0]

# 最后一组水瓶的结果展示
items = list(end_bottle.items())
items.sort(key=lambda x: x[1], reverse=True)
for i in range(len(items)):
    way_sorted, water_sortd = items[i]
    print('{0:<10}{1:>5}'.format(way_sorted, water_sortd))
